<?php

if (version_compare(phpversion(), "5.3.0", ">=")  == 1)
  error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
else
  error_reporting(E_ALL & ~E_NOTICE); 

require_once('classes/CMySQL.php');

$sParam = $GLOBALS['MySQL']->escape($_GET['q']); // escaping external data
if (! $sParam) exit;

switch ($_GET['mode']) {
    case 'location': // using database as source of data
        $sRequest = "SELECT `itemlocationName` FROM `itemlocation` WHERE `itemlocationName` LIKE '%{$sParam}%' ORDER BY `itemlocationName`";
        $aItemInfo = $GLOBALS['MySQL']->getAll($sRequest);
        foreach ($aItemInfo as $aValues) {
            echo $aValues['itemlocationName'] . "\n";
        }
        break;
        
    case 'sql': // using database as source of data
        $sRequest = "SELECT `itemName` FROM `item` WHERE `itemName` LIKE '%{$sParam}%' ORDER BY `itemName`";
        $aItemInfo = $GLOBALS['MySQL']->getAll($sRequest);
        foreach ($aItemInfo as $aValues) {
            echo $aValues['itemName'] . "\n";
        }
        break;
        
    case 'transaction': // using database as source of data
        $sRequest = "SELECT transactionIn 
                       FROM transactionin 
                      WHERE transactionIn 
                       LIKE '%{$sParam}%' 
                      ORDER BY transactionIn";
        $aItemInfo = $GLOBALS['MySQL']->getAll($sRequest);
        foreach ($aItemInfo as $aValues) {
            echo $aValues['transactionIn'] . "\n";
        }
        break;
}